<?php
$path = dirname(__FILE__);
if( strpos( $path, '/' ) !== false ) $path = explode("/", $path);
else $path = explode("\\", $path);
array_pop($path);
$path = implode("/", $path);
$dir_name = '.svn';


function scan($path, $dir_name, $level = 0){
	static $dirsToRemove = array();
	{
		$rdi=new DirectoryIterator($path);
		foreach($rdi as $obj){
			if(!$obj->isDot() && $obj->isDir()){
				if( strcmp($obj->getFilename(), $dir_name)== 0 )
					$dirsToRemove[] = $obj->getPathname();
				else
				 scan($obj->getPathname(), $dir_name, $level+1);
			}
		}
	}
	if ($level == 0)
	foreach ($dirsToRemove as $obj){
		print_r('Usuwanie '.$obj.'<br />');
		remove_dir($obj);
	}
}

function remove_dir($path){
	$di=new DirectoryIterator($path);
	foreach($di as $obj){	
		if(!$obj->isDot()){
			$name = $obj->getPathname();
		
			if($obj->isDir()){
				remove_dir($name);
			}else{
				@chmod( $name, 0777 );		
				unlink($name);
			}
		}
	}			
	@chmod( $path, 0777 );
	rmdir( $path );
}

scan($path, $dir_name);

?>